package com.qyer.commons.service.model;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.qyer.commons.place.QyerPlace;

import java.util.List;
import java.util.Map;

/**
 * User: Z J Wu Date: 2016/03/06 Time: 01:57 Package: com.qyer.commons.service.model
 * <p/>
 * NOT thread safe
 */
public class PlaceDict<K, P extends QyerPlace> {

  private int defaultSize;

  private Map<K, List<P>> placeMap;

  public PlaceDict(int defaultSize, int mapSize) {
    this.defaultSize = defaultSize;
    this.placeMap = Maps.newHashMapWithExpectedSize(mapSize);
  }

  public void putPlace(K key, P qyerPlace) {
    List<P> list = placeMap.get(key);
    if (list == null) {
      list = Lists.newArrayListWithExpectedSize(defaultSize);
      placeMap.put(key, list);
    }
    list.add(qyerPlace);
  }

  public List<P> get(K key) {
    return placeMap.get(key);
  }

}
